/**
 * @author LKQ
 * @date 2021/12/27 14:26
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = {17, 18, 5, 4, 6, 1};
        solution.replaceElements(arr);
    }

    public int[] replaceElements(int[] arr) {
        int n = arr.length;
        if (n == 1) {
            arr[0] = -1;
            return arr;
        }
        for (int i = 0; i < n; i++) {
            if (i < n - 1) {
                arr[i] = Max(arr, i+1, n);
            }else {
                arr[i] = -1;
            }

        }
        return arr;
    }

    public int Max(int[] arr, int start, int end ) {
        int ans = arr[start];
        for (int i = start; i < end ; i++) {
            if (arr[i] > ans) {
                ans = arr[i];
            }
        }
        return ans;
    }
}
